package dnl.util.ui.actions;

import java.awt.event.ActionEvent;

import javax.swing.ImageIcon;


@SuppressWarnings("serial")
public abstract class AbstractAction
  extends javax.swing.AbstractAction
  implements Runnable {

  //~ Constructors ............................................................


  /**
   * Creates a new AbstractAction object.
   */
  public AbstractAction(String name) {
    super(name);
    this.name = name;
  }

  /**
   * Creates a new AbstractAction object.
   */
  public AbstractAction(String name, boolean threaded) {
    super(name);
    this.threaded = threaded;
    this.name = name;
  }

	/**
	 * 
	 * @param name
	 * @param icon
	 * @param threaded
	 */
  public AbstractAction(String name, ImageIcon icon, boolean threaded) {
    super(name, icon);
    this.threaded = threaded;
    this.name = name;
  }

  //~ Methods .................................................................

  /**
   *
   * @param e
   */
  @Override
public synchronized void actionPerformed(ActionEvent e) {
    if( threaded ){
      this.aEvent = e;
      new Thread(this).start();
    }
    else
      actionPerformedImpl(e);
  }


  public abstract void actionPerformedImpl(ActionEvent e);

  @Override
public void run(){
    actionPerformedImpl(aEvent);
  }

  public String getName() {
    return name;
  }

  //~ Instance/static variables ...............................................

  protected boolean threaded;
  private ActionEvent aEvent;
  private String name;
}